jQuery(document).ready(function(){
	jQuery('.msg_body:not(:first)').hide();
	jQuery('div.right-tab:first').addClass('right-tab-active');
	jQuery('div.left-tab:first').addClass('left-tab-active');
	jQuery('div.center-tab:first').addClass('center-tab-active');
	//when the anchor is clicked content gets faded
	jQuery("div.right-tab").mouseover(function(){
		jQuery('.msg_body').hide();
		jQuery(jQuery('>>>> a.linkclass',this).attr("rel")).show();
		//jQuery('.msg_body').fadeOut("fast");
		//jQuery(jQuery('>>>> a.linkclass',this).attr("rel")).fadeIn("slow");
		jQuery('.right-tab-active').removeClass("right-tab-active");
		jQuery('.left-tab-active').removeClass("left-tab-active");
		jQuery('.center-tab-active').removeClass("center-tab-active");
		jQuery(this).addClass("right-tab-active");
		jQuery('> .left-tab',this).addClass("left-tab-active");
		jQuery('>> .center-tab',this).addClass("center-tab-active");
		
	});
	/* dropdown menu*/
	jQuery("ul.dropdown li").hover(function(){
		jQuery(this).addClass("hover");
		jQuery('> .dir',this).addClass("open");
		jQuery('ul:first',this).css('visibility', 'visible');
	},function(){
		jQuery(this).removeClass("hover");
		jQuery('.open',this).removeClass("open");
		jQuery('ul:first',this).css('visibility', 'hidden');
	});
	
});

// slide menu
//jQuery('#slideshow IMG:first').addClass('active');
function slideSwitch() {
    var jQueryactive = jQuery('#slideshow IMG.active');
    if ( jQueryactive.length == 0 ) jQueryactive = jQuery('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var jQuerynext =  jQueryactive.next().length ? jQueryactive.next()
        : jQuery('#slideshow IMG:first');

    jQueryactive.addClass('last-active');

    jQuerynext.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            jQueryactive.removeClass('active last-active');
        });
}

jQuery(function() {
    setInterval( "slideSwitch()", 5000 );
});

// cookies
jQuery.cookie=function(B,I,L){if(typeof I!="undefined"){L=L||{};if(I===null){I="";L.expires=-1}var E="";if(L.expires&&(typeof L.expires=="number"||L.expires.toUTCString)){var F;if(typeof L.expires=="number"){F=new Date();F.setTime(F.getTime()+(L.expires*24*60*60*1000))}else{F=L.expires}E="; expires="+F.toUTCString()}var K=L.path?"; path="+(L.path):"";var G=L.domain?"; domain="+(L.domain):"";var A=L.secure?"; secure":"";document.cookie=[B,"=",encodeURIComponent(I),E,K,G,A].join("")}else{var D=null;if(document.cookie&&document.cookie!=""){var J=document.cookie.split(";");for(var H=0;H<J.length;H++){var C=jQuery.trim(J[H]);if(C.substring(0,B.length+1)==(B+"=")){D=decodeURIComponent(C.substring(B.length+1));break}}}return D}};

// poll effect
/*var OPT_ID = 0;
var OPT_TITLE = 1;
var OPT_VOTES = 2;
var STUID = 3;

var votedID;

jQuery(document).ready(function(){
  jQuery("#poll").submit(formProcess);  // setup the submit handler
    
  if (jQuery("#poll-results").length > 0 ) {
    animateResults();
  }
  
  if (jQuery.cookie('vote_id')) {
    jQuery("#poll-container").empty();
    votedID = jQuery.cookie('vote_id');
	//thay doi doung dan khi hoan thanh
    jQuery.getJSON("http://tieuhocso3-phuocthoi.edu.vn/com_poll",loadResults);
  }
});

function formProcess(event){
  event.preventDefault();
  //get value checked radio button 
  var id = jQuery("input[@name='poll']:checked").attr("value");
  //id = id.replace("opt",'');
  
  jQuery("#poll-container").fadeOut("slow",function(){
    jQuery(this).empty();
    
    votedID = id;
    jQuery.getJSON("http://tieuhocso3-phuocthoi.edu.vn/com_poll" + id,loadResults);
    
    jQuery.cookie('vote_id', id, {expires: 365});
    });
}

function animateResults(){
  jQuery("#poll-results div").each(function(){
      var percentage = jQuery(this).next().text();
      jQuery(this).css({width: "0%"}).animate({
				width: percentage}, 'slow');
  });
}

function loadResults(data) {
  var total_votes = 0;
  var percent;
  
  for (i=0; i<data.length; i++) {
    total_votes = total_votes+parseInt(data[i][OPT_VOTES]);
  }
  
  var results_html = "<div id='poll-results'>\n<dl class='graph'>\n";
  for (i=0; i<data.length; i++) {
    percent = Math.round((parseInt(data[i][OPT_VOTES])/parseInt(total_votes))*100);
    if (data[i][OPT_ID] !== votedID) {
      results_html = results_html+"<dt class='bar-title'>"+data[i][OPT_TITLE] +": "+ data[i][OPT_VOTES]+" lượt</dt><dd class='bar-container'><div id='bar"+data[i][OPT_ID]+"'style='width:0%;'></div><strong>"+percent+"%</strong></dd>\n";
    } else {
      results_html = results_html+"<dt class='bar-title'>"+data[i][OPT_TITLE] +": "+ data[i][OPT_VOTES]+" lượt</dt><dd class='bar-container'><div id='bar"+data[i][OPT_ID]+"'style='width:0%;background-color:red;'></div><strong>"+percent+"%</strong></dd>\n";
    }
  }
  
  results_html = results_html+"</dl><p>Tổng số bình chọn: "+total_votes+"</p></div>\n";
  
  jQuery("#poll-container").append(results_html).fadeIn("slow",function(){
    animateResults();});

}*/

/*drop down thief*/
$(document).ready(function() { 

$("#nav1 li").hover(function(){ 

        $(this).find('ul:first').css({visibility: "visible",display: "none"}).show(100); 
        },function(){ 
        $(this).find('ul:first').css({visibility: "hidden"}); 

        }); 
});
/*end drop down thief*/


var dayarray=new Array ("Chủ nhật", "Thứ hai", "Thứ ba", "Thứ tư", "Thứ năm", "Thứ sáu", "Thứ bảy")

var montharray=new Array("Tháng 1","Tháng 2","Tháng 3","Tháng 4","Tháng 5","Tháng 6","Tháng 7","Tháng 8","Tháng 9","Tháng 10","Tháng 11","Tháng 12")

function getthedate(){

var mydate=new Date()

var year=mydate.getYear()

if (year < 1000)

year+=1900

var day=mydate.getDay()

var month=mydate.getMonth()

var daym=mydate.getDate()

if (daym<10)

daym="0"+daym

var hours=mydate.getHours()

var minutes=mydate.getMinutes()

var seconds=mydate.getSeconds()

var dn=""

if (hours>=12)

dn=""

if (hours>12){

hours=hours

}

if (hours==0)

hours=12

if (minutes<=9)

minutes="0"+minutes

if (seconds<=9)

seconds="0"+seconds

//Hire change font size

var cdate=dayarray[day]+", "+daym+" "+montharray[month]+", "+year+" - "+hours+":"+minutes+":"+seconds+" "+dn

if (document.all)

document.all.clock.innerHTML=cdate

else if (document.getElementById)

document.getElementById("clock").innerHTML=cdate

else

document.write(cdate)

}

if (!document.all&&!document.getElementById)

getthedate()

function goforit(){

if (document.all||document.getElementById)

setInterval("getthedate()",1000)

}

goforit();

